package com.fei.yuan.myapplication.utils;

import com.fei.yuan.myapplication.database.FormBean;
import ohos.data.orm.OrmContext;
import ohos.data.orm.OrmPredicates;

import java.util.List;

/**
 * @since 2021-07-20
 */
public class DatabaseUtils {

    /**
     * 添加卡片信息到数据库
     *
     * @param formBean
     * @param ormContext
     */
    public static void insertForm(FormBean formBean, OrmContext ormContext){
        ormContext.insert(formBean);
        ormContext.flush();
    }

    /**
     * 删除卡片信息
     *
     * @param formId
     * @param ormContext
     */
    public static void deleteFormData(long formId,OrmContext ormContext){
        OrmPredicates where = ormContext.where(FormBean.class);
        where.equalTo("formId",formId);
        List<FormBean> query = ormContext.query(where);
        if (!query.isEmpty()){
            ormContext.delete(query.get(0));
            ormContext.flush();
        }

    }
}
